package com.yz.newspaper.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.yz.newspaper.mapper.UnitSignMapper;
import com.yz.newspaper.pojo.po.UnitSign;
import com.yz.newspaper.service.IUnitSignService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 联合署名表 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-04-21
 */
@Service
public class UnitSignServiceImpl extends ServiceImpl<UnitSignMapper, UnitSign> implements IUnitSignService {

    @Override
    public Map<Integer, List<UnitSign>> getAll() {

        List<Integer> unitNums = baseMapper.groupUnitNum();
        Map<Integer, List<UnitSign>> map = new HashMap<>();

        unitNums.forEach(item -> {
            List<UnitSign> unitSigns = baseMapper.selectList(new LambdaUpdateWrapper<UnitSign>()
                    .eq(UnitSign::getUnitNum, item));
            map.put(item, unitSigns);
        });
        return map;
    }
}
